﻿@{
    Layout = null;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <style>
        .right {
            display: none;
        }
        .row{
            display: none;
        }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link href="~/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/css/style.css" />
    <link href="~/assets/css/codemirror.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/assets/css/ace.min.css" />
    <link rel="stylesheet" href="~/font/css/font-awesome.min.css" />
    <link rel="stylesheet" href="~/layui-v2.5.4/layui/css/layui.css" />
    <!--[if lte IE 8]>
      <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
    <![endif]-->
    <script src="~/Scripts/jquery-1.9.1.min.js"></script>
    <script src="~/assets/js/bootstrap.min.js"></script>
    <script src="~/assets/js/typeahead-bs2.min.js"></script>
    <script src="~/assets/js/jquery.dataTables.min.js"></script>
    <script src="~/assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="~/assets/layer/layer.js" type="text/javascript"></script>
    <script src="~/assets/laydate/laydate.js" type="text/javascript"></script>
    <script src="~/Scripts/Format.js" type="text/javascript"></script>
    <script src="~/layui-v2.5.4/layui/layui.js" type="text/javascript"></script>
    <title>用户积分管理</title>
</head>

<body>
    <div class="margin clearfix">
        <div class="" id="Other_Management">
            @*<div class="search_style">

            <ul class="search_content clearfix">
                <li><label class="l_f">会员名称</label><input name="" id="id" type="text" class="text_add" placeholder="输入会员名称、电话、邮箱" style=" width:400px" /></li>
                <li style="width:90px;"><button type="button" class="btn_search" id="checkName"><i class="fa fa-search"></i>查询</button></li>
            </ul>
        </div>*@
            @*<div class="border clearfix">
            <span class="l_f">
                <a href="javascript:ovid()" class="btn btn-danger id="batchDelete"><i class="fa fa-trash"></i>&nbsp;批量删除</a>
            </span>
            <span class="r_f">共：<b>2345</b>条</span>
        </div>*@
            <div class="border clearfix">
                <span class="l_f">
                    <a href="javascript:ovid()" class="btn btn-danger" id="batchDelete"><i class="fa fa-trash"></i>&nbsp;批量删除</a>
                </span>
                @*<span class="r_f">共：<b>2345</b>条</span>*@
            </div>
            <div class="right" id="app">
                <fieldset class="layui-elem-field layui-field-title">
                    @*<legend>添加用户</legend>*@
                </fieldset>
                <form class="layui-form ">
                    <input type="hidden" name="Integral_Id" id="Integral_Id" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                    <div class="layui-form-item">
                        <label class="layui-form-label">积分编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="User_Id" id="User_Id" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">积分余额</label>
                        <div class="layui-input-block">
                            <input type="text" name="Integral_balance" id="Integral_balance" required=required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" />
                        </div>
                    </div>

                    <div class="layui-form-item" id="isvip">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <input type="checkbox" value="1" id="Integral_State" name="Integral_State" lay-text="开启|关闭" checked="" lay-skin="switch" lay-filter="switchEnable" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="button" id="commit" value="立即提交" class="layui-btn" />
                        </div>
                    </div>


                </form>
            </div>
            <div class="list_style">
                @*<table class="table table-striped table-bordered table-hover" id="sample-table"> </table>*@
                <table class="layui-hide" id="sample-table" lay-filter="demo"></table>
                <script id="barDemo" type="text/html">
                    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="Sev">添加</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                </script>

            </div>

        </div>
    </div>
   
</body>
</html>
<script>
    jQuery(function ($) {
        var oTable1 = $('#sample-table').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                { "orderable": false, "aTargets": [0, 2, 3, 6] }// 制定列不参与排序
            ]
        });


        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });
    });



    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $(obj).parents("tr").remove();
            layer.msg('已删除!', { icon: 1, time: 1000 });
        });
    }
    //积分浏览
    function integration_history(id) {
        layer.open({
            type: 1,
            title: '积分获取记录',
            area: ['800px', '400px'],
            shadeClose: true,
            content: $('#integration_history'),
        })
        $('#integration_history_list').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [{
                "bSortable": false,
                "orderable": false,
                "aTargets": [0, 1]
            }]
        });

    };
    //浏览记录

    function Browse_history(id) {
        layer.open({
            type: 1,
            title: '浏览记录',
            area: ['800px', '400px'],
            shadeClose: true,
            content: $('#Browse_history'),
        })
        $('#Browse_history_list').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [{
                "bSortable": false,
                "orderable": false,
                "aTargets": [0, 1]
            }]
        });
    }


    //购物记录
    function Order_history(id) {
        layer.open({
            type: 1,
            title: '购物记录',
            area: ['800px', '400px'],
            shadeClose: true,
            content: $('#Order_history'),
        });
        $('#Order_history_list').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [{
                "bSortable": false,
                "orderable": false,
                "aTargets": [0, 1]
            }]
        });
    }


</script>
<script>
         //列表刷新
        function TableReload() {
            var table = layui.table;
            var id = $("#id").val();
            //上述方法等价于
            table.reload('sample-table', {
                where: { //设定异步数据接口的额外参数，任意设
                    id: id              
                }
            });
        }

        //查询按钮点击事件
        $("#checkName").click(function () {
            //调用列表刷新方法
            TableReload();
           
        });

    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;  //启用
        table.render({
            elem: '#sample-table'
            , url: '/Integral/GetIntegralPageList/'
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , cols: [[
                { type: 'checkbox' }
                , { field: 'Integral_Id', width: 110, align: 'center', title: '积分编号', sort: true }
                , { field: 'User_Id', width: 110, align: 'center', title: '用户编号' }
                , { field: 'Integral_balance', width: 110, align: 'center', title: '积分余额', sort: true }
                //, { field: 'Questions_Content', width: 150, align: 'center', title: '提问内容' }
                //, { field: 'Questions_Count', width: 100, align: 'center', title: '回复数' }
                , { field: 'Integral_State', title: '状态', width: 120, templet: '#switchTpl', unresize: true }
                , { field: 'Integral_UpdateTime', width: 180, align: 'center', title: '修改时间', templet: "<div>{{Format(d.Integral_UpdateTime,'yyyy-MM-dd')}}</div>" }
                , { field: 'Integral_CreateTime', width: 180, align: 'center', title: '创建时间', templet: "<div>{{Format(d.Integral_CreateTime,'yyyy-MM-dd')}}</div>" }
                , { fixed: 'right', title: '操作', width: 208, align: 'center', toolbar: '#barDemo' }
            ]]
            , page: true
            , id: 'sample-table'
        });

        //状态
        form.on('switch(switchShow)', function (obj) {
            var tip = "启用";
            var id = this.id;
            var status = this.value;

            if (this.value === "1") {
                tip = "停用";
                status = 0;
            } else {
                status = 1;
            }

            layer.confirm('真的要' + tip + '吗', function (index) {
                $.ajax({
                    url: "/Integral/UpdateStatus?id=" + id + "&status=" + status,
                    type: "post",
                    success: function (result) {
                        if (result.Sueess) {
                            layer.msg(tip + '失败！', { title: '提示框', icon: 1, time: 2000 }, function () { window.location.reload() });
                        } else {
                            layer.msg(tip + '成功！');
                        }
                    }
                })
            })
        });
        //删除
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            var id = data.Integral_Id;
            if (obj.event === 'del') {

                //删除的功能代码
                layer.confirm('真的要删除吗', function (index) {
                    $.ajax({
                        url: "/Integral/DelIntegral?id=" + id,
                        type: "Post",
                        success: function (data) {
                            if (data.Success) {
                                layer.msg('删除成功！', {
                                    title: '提示框',
                                    icon: 1,
                                    time: 2000

                                }, function () {
                                    TableReload();
                                    //layer.close(index);
                                });
                                location.reload();
                            }
                            else {
                                layer.msg('删除失败！', {
                                    title: '提示框',
                                    icon: 1,
                                    time: 2000
                                });
                            }
                        }
                    });
                });
            } else if (obj.event === 'Sev') {
                layer.open({
                    type: 1,
                    title: '添加信息',
                    area: ['800px', ''],
                    shadeClose: false,
                    content: $("#app"),
                });
                $("#User_Id").val(null);
                $("#Integral_balance").val(null);
                $("#Integral_State").val(null);

                //添加按钮点击事件
                $("#commit").click(function () {
                    var data = {};
                    data.User_Id = $("#User_Id").val();
                    data.Integral_balance = $("#Integral_balance").val();

                    data.Integral_State = 0;
                    if ($("#Integral_State").prop("checked")) {
                        data.Integral_State = 1;
                    }
                    $.ajax({
                        url: "/Integral/AddIntegral",
                        type: "post",
                        data: data,
                        success: function (result) {
                            if (result.Success) {
                                layer.msg('新增成功！',
                                    {
                                        icon: 1,
                                        time: 2000,
                                        shade: 0.2
                                    }, function () {
                                        window.location.href = "/Home/Integral"
                                    });
                            }
                            else {
                                layer.msg('新增失败！',
                                    {
                                        icon: 1,
                                        time: 2000,
                                        shade: 0.2
                                    });
                            }
                        }
                    })
                });
            } else if (obj.event === 'edit') {
                layer.open({
                    type: 1,
                    title: '修改信息',
                    area: ['800px', ''],
                    shadeClose: false,
                    content: $("#app"),
                });
                $("#Integral_Id").val(data.Integral_Id);
                $("#User_Id").val(data.User_Id);
                $("#Integral_balance").val(data.Integral_balance);



                if (data.Integral_State === 1) {
                    $("#isvip em").text("是");
                    $("#isvip .layui-form-switch").addClass("layui-form-onswitch");
                } else {
                    $("#isvip em").text("否");
                    $("#isvip .layui-form-switch").removeClass("layui-form-onswitch");
                }

                $("#commit").click(function () {
                    var Questions = {};
                    Questions.Integral_Id = $("#Integral_Id").val();
                    Questions.User_Id = $("#User_Id").val();
                    Questions.Integral_balance = $("#Integral_balance").val();
                   

                    if ($("#Integral_State").prop("checked")) {
                        Questions.Integral_State = 1;
                    } else {
                        Questions.Integral_State = 0;
                    }

                    $.ajax({
                        type: "post",
                        data: Questions,
                        url: "/Integral/UpdateIntegral",
                        success: function (result) {
                            if (result.Success) {
                                layer.msg('修改成功！', {
                                    title: '提示框',
                                    icon: 1,
                                    time: 2000
                                }
                                    , function () { window.location.reload() });
                            } else {
                                layer.msg('修改失败！', {
                                    title: '提示框',
                                    icon: 1,
                                    time: 2000
                                });
                            }
                        }
                    });
                });
            }
        });
        //批量删除
        $("#batchDelete").click(function () {
            //获取复选框集合数据
            var checkStatus = table.checkStatus('sample-table');
            var data = checkStatus.data;
            //获得where限制条件Id
            var codeId = "";
            if (data.length == 0) {
                layer.msg('请选择一行', {
                    title: '提示框',
                    icon: 0,
                    time: 2000

                });
                return;
            };
            //遍历集合,拼接字符串
            for (var i in data) {
                if (i == data.length - 1) {
                    codeId += data[i].Integral_Id
                } else {
                    codeId += data[i].Integral_Id + ",";

                }
            };
            //温馨提示是否要删除
            $.ajax({
                url: "/Integral/BatchDeleteIntegral?Id=" + codeId,
                traditional: true,
                type: "post",
                success: function (operate) {
                    if (operate.Success) {
                        layer.msg('批量删除成功!！', {
                            title: '提示框',
                            icon: 1,
                            time: 400
                        })
                        location.reload();//刷新页面
                    }
                    else {
                        layer.msg('批量删除失败！', {
                            title: '提示框',
                            icon: 1,
                            time: 400
                        })
                    }
                }
            })
        })
    });
</script>
<script type="text/html" id="switchTpl">
    <input type="checkbox" id="{{d.Integral_Id}}" name="sex" value="{{d.Integral_State}}" lay-skin="switch" lay-text="是|否" lay-filter="switchShow" {{ d.Integral_State == 1 ? 'checked' : '' }} />
</script>
